package com.ebupt.migu.music.commons.selfdom.demo.impl;

import com.ebupt.migu.globalpopup.entity.ConditionRelation;
import com.ebupt.migu.globalpopup.enums.ConditionEnum;
import com.ebupt.migu.music.commons.selfdom.demo.Equipment;
import com.ebupt.migu.music.commons.selfdom.demo.impl.identifier.AbstractIdentifierImpl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
 * 设备信息子条件实现类
 *
 * @author wangzhu
 * @since 2021-12-31
 */
public class EquipmenImpl extends AbstractIdentifierImpl implements Equipment {
    /**
     * 设备型号（如：apple/iPhone 6s Plus）
     */
    private boolean model(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * 操作系统（如： iOS）
     */
    private boolean system(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * 操作系统版本（如： iOS/13.3.1）
     */
    private boolean sysVrsion(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * idfa
     */
    private boolean idfa(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * Android_id
     */
    private boolean androidId(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * OAID
     */
    private boolean OAID(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * 手机品牌（如Huawei）
     */

    private boolean phoneBrand(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * ua（Ios_migu，Ios_migu_iPad，Android_migu）
     */

    private boolean ua(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * 更具不同的子条件判断返回判断结果（子条件第一版只支持or）
     */
    @Override
    public boolean getEquipmen(Map data, List<ConditionRelation> conditionRelations) {
        LinkedHashMap<Boolean, Integer> booleanIntegerLinkedHashMap = new LinkedHashMap<>();
        // 排序
        super.sort(conditionRelations);
        for (ConditionRelation conditionRelation : conditionRelations) {
            boolean equipmen = true;
            Object o = data.get(ConditionEnum.getKeyValue(conditionRelation.getPropertyCode(), conditionRelation.getConditionKey()));
            if (o==null||o.equals("")) {
                equipmen=false;
                booleanIntegerLinkedHashMap.put(equipmen,conditionRelation.getCConnector());
                break;
            }
            String value = o.toString();
            switch (conditionRelation.getConditionKey()) {
                case 1:
                    equipmen = this.model(value, conditionRelation,conditionRelation.getConditionKey());

                    break;
                case 2:
                    equipmen = this.system(value, conditionRelation,conditionRelation.getConditionKey());

                    break;
                case 3:
                    equipmen = this.sysVrsion(value, conditionRelation,conditionRelation.getConditionKey());

                    break;
                case 4:
                    equipmen = this.idfa(value, conditionRelation,conditionRelation.getConditionKey());

                    break;
                case 5:
                    equipmen = this.androidId(value, conditionRelation,conditionRelation.getConditionKey());

                    break;
                case 6:
                    equipmen = this.OAID(value, conditionRelation,conditionRelation.getConditionKey());

                    break;
                case 7:
                    equipmen = this.phoneBrand(value, conditionRelation,conditionRelation.getConditionKey());

                    break;
                case 8:
                    equipmen = this.ua(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                default:
                    break;
            }
            booleanIntegerLinkedHashMap.put(equipmen, conditionRelation.getCConnector());
        }
        return super.getRelation(booleanIntegerLinkedHashMap);
    }
}
